package com.boge.ai.prompt;

import okhttp3.*;

import java.io.IOException;
import java.util.concurrent.TimeUnit;

public class Demo2 {
    public static void main(String[] args) throws IOException {
        OkHttpClient client = new OkHttpClient().newBuilder()
                .readTimeout(20, TimeUnit.SECONDS)
                .connectTimeout(20, TimeUnit.SECONDS)
                .build();
        MediaType mediaType = MediaType.parse("application/json");

        String prompt = "提取以下文本中的地名。" +
                "所需格式：" +
                "地点：<逗号分隔的公司名称列表>" +
                "输入：“虽然这些发展对研究人员来说是令人鼓舞的，但仍有许多谜团。里斯本未知的香帕利莫德中心的神经免疫学家 Henrique Veiga-Fernandes 说：“我们经常在大脑和我们在周围看到的效果之间有一个黑匣子。”“如果我们想在治疗背景下使用它，我们实际上需要了解机制。””";
        String promptMsg = String.format("""
                {
                        "model": "gpt-4o",
                        "messages": [
                            {
                                "role": "user",
                                "content": "%s"
                            }
                        ]
                }
        """,prompt);

        //RequestBody body = RequestBody.create(mediaType, "{\n  \"messages\": [\n    {\n      \"content\": \"You are a helpful assistant\",\n      \"role\": \"system\"\n    },\n    {\n      \"content\": \"你好啊，你能介绍下中国吗?>\",\n      \"role\": \"user\"\n    }\n  ],\n  \"model\": \"gpt-4o\"}");
        RequestBody body = RequestBody.create(mediaType, promptMsg);
        Request request = new Request.Builder()
                .url("https://api.openai-hk.com/v1/chat/completions")
                .method("POST", body)
                .addHeader("Content-Type", "application/json")
                .addHeader("Accept", "application/json")
                .addHeader("Authorization", "Bearer hk-w3q3id1000054953c829f33c861457133e3048fa220f1076")
                .build();
        Response response = client.newCall(request).execute();
        System.out.println(response.body().string());
    }
}
